package com.gjy.disruptor.uuid.dec.disruptor;

import com.fasterxml.uuid.impl.RandomBasedGenerator;
import com.lmax.disruptor.EventTranslatorOneArg;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 事件转换器，将UUID生成器和数据放入事件中。
 *
 * @author gjy
 * @version 1.0
 * @since 2025-10-11 09:14:34
 */
public class UuidEventTranslator implements EventTranslatorOneArg<UuidEvent, RandomBasedGenerator> {
    private static final Logger log = LoggerFactory.getLogger(UuidEventTranslator.class);
    public static final UuidEventTranslator INSTANCE = new UuidEventTranslator();

    private UuidEventTranslator() {
    }

    @Override
    public void translateTo(UuidEvent event, long sequence, RandomBasedGenerator generator) {
        // 在这里生成UUID并设置到事件中
        String uuid = generator.generate().toString();
        log.info("生成的UUID: {}", uuid);
        event.setUuid(uuid);
    }
}
